package com.htgd.gardenexpo.controller;


import com.htgd.gardenexpo.entity.CommonResult;
import com.htgd.gardenexpo.entity.GeConLeisureDataDeck;
import com.htgd.gardenexpo.entity.GeConLeisurePrize;
import com.htgd.gardenexpo.service.IGeConLeisureDataDeckService;
import com.htgd.gardenexpo.service.IGeConLeisureDataDeckTaskService;
import com.htgd.gardenexpo.utils.TokenUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 挑战甲板数据 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-04-03
 */
@RestController
@RequestMapping("/api/leisureDataDeck")
@Api(tags = "挑战甲板数据")
@Slf4j
public class GeConLeisureDataDeckController {

    @Autowired
    private IGeConLeisureDataDeckService geConLeisureDataDeckService;

    @Autowired
    private IGeConLeisureDataDeckTaskService geConLeisureDataDeckTaskService;

    @PostMapping(value = "/add")
    @ApiOperation("添加")
    public CommonResult add(@RequestBody GeConLeisureDataDeck geConLeisureDataDeck) {
        log.info("挑战甲板数据-添加：{}",geConLeisureDataDeck);
        return geConLeisureDataDeckService.add(geConLeisureDataDeck);
    }

    @PutMapping(value = "/updateStatus")
    @ApiOperation("更新任务状态")
    public CommonResult updateStatus(@RequestParam(value = "taskId")String taskId) {
        log.info("挑战甲板数据-更新任务状态：{}",taskId);
        return geConLeisureDataDeckTaskService.updateStatus(taskId);
    }

    @GetMapping(value = "/getTaskDetails")
    @ApiOperation("获取任务详情")
    public CommonResult getTaskDetails(@RequestParam(value = "taskId") String taskId) {
        log.info("挑战甲板数据-获取任务详情：{}",taskId);
        return geConLeisureDataDeckService.getTaskDetails(taskId);
    }

    @GetMapping(value = "/getMyList")
    @ApiOperation("我的挑战列表")
    public CommonResult getMyList(@RequestParam(defaultValue = "1") Integer pageNum,
                                  @RequestParam(defaultValue = "10") Integer pageSize,
                                  HttpServletRequest request) {
        String accessToken = request.getHeader("Access_token");
        String openId = TokenUtil.getUsernameFromToken(accessToken);
        log.info("我的挑战列表：{},{},{}",openId,pageNum,pageSize);
        return geConLeisureDataDeckService.getMyList(openId,pageNum,pageSize);
    }

}
